package 机试题16年;

import java.util.Scanner;

/**
 * Created by hest0 on 2017/4/19.
 */
public class 最后一个字符 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int t = sc.nextInt();
            for (int i = 0; i < t; i++) {
                String s = sc.next();
                System.out.println(findFirstUnique(s));
            }
        }
        sc.close();
    }

    private static char findFirstUnique(String str) {
        char[] ch = str.toCharArray();
        int[] map = new int[127];
        for (char c : ch) {
            map[c]++;
        }
        for (char c : ch) {
            if (map[c] == 1) {
                return c;
            }
        }
        return 0;
    }

}
